OpenGL 3.3 different colours with fragment shader [solved]

Posted by Andrew Seymour on Stack Overflow See other posts from Stack Overflow or by Andrew Seymour
Published on 2013-11-02T16:38:27Z Indexed on 2013/11/03 15:53 UTC
Read the original article Hit count: 208

Filed under:
|
|
|
|

I'm an OpenGL newbie. I'm trying to colour 3 circles but only 3 white circles are appearing. n is 3 in this example. Each vertice has 5 points, 2 for position and 3 for color

Here is where I think a problem may lie:

    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glVertexAttribPointer(
        0,                  
        2,                 
        GL_FLOAT,           
        GL_FALSE,          
        5*sizeof(float), 
        (void*)0            
    );

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(
        1, 
        3,
        GL_FLOAT,
        GL_FALSE, 
        5*sizeof(float), 
        (void*)(2*sizeof(float))
    );

    glDrawElements(GL_TRIANGLES, 20 * 3 * n, GL_UNSIGNED_INT, 0);

    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

My shaders:

#version 330 core

in vec3 Color;

out vec4 outColor;

void main()
{
    outColor = vec4(Color, 1.0);
}


#version 330 core

layout(location = 0) in vec2 position;

layout(location = 1) in vec3 color
out vec3 Color

void main(){
    gl_Position = vec4(position, 0.0, 1.0);
    Color = color;
}

Thanks for taking a look Andy

EDIT:

layout(location = 1) in vec3 color
    out vec3 Color

layout(location = 1) in vec3 color;
    out vec3 Color;

© Stack Overflow or respective owner

Related posts about c++

Related posts about opengl